package com.ymatou.iapi.trading.userquery.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.CollectionUtils;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.req.BizVo;
import com.ymatou.iapi.trading.operate.parameter.req.ChangeOrderBizStatusBean;
import com.ymatou.iapi.trading.operate.service.ChangeOrderBizStatusCall;
import com.ymatou.iapi.trading.operate.testcase.Ts_ChangeOrderBizStatus;
import com.ymatou.iapi.trading.ordersync.service.SyncVerifyService;
import com.ymatou.iapi.trading.userquery.parameter.resp.GetBuyerOrderInfosResp;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.BargainGroupStatusEnum;
import com.ymttest.common.enums.BargainGroupSubTypeEnum;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.common.order.userquery.OrderInfoBuilder;
import com.ymttest.common.order.userquery.model.vo.BargainGroupInfo;
import com.ymttest.common.order.userquery.model.vo.OrderInfo;
import com.ymttest.database.model.mongo.query.Order;
import com.ymttest.database.model.mongo.query.UserIndex;
import com.ymttest.database.mongo.OrderQueryWapper;
import com.ymttest.database.mongo.UserIndexQueryWapper;
import com.ymttest.database.mongo.config.MongoOrderConfig;
import com.ymttest.database.mongo.config.OrderField;
import com.ymttest.database.mongo.config.SchemaField;
import com.ymttest.database.mongo.config.UserIndexField;
import com.ymttest.database.mongo.converter.ConvertUtils;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 获取买家订单列表
 */
@TestSuite
public class Ts_GetBuyerOrderInfosV2 {

	private static com.ymatou.iapi.trading.userquery.parameter.GetBuyerOrderInfosBean req;
	private static com.ymatou.iapi.trading.userquery.service.GetBuyerOrderInfosV2Call call;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家订单列表");
	}

	@Before
	public void caseUp() {
		req = new com.ymatou.iapi.trading.userquery.parameter.GetBuyerOrderInfosBean();
		call = new com.ymatou.iapi.trading.userquery.service.GetBuyerOrderInfosV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private List<Order> getBuyerOrders(List<Criteria> criteriaList) {
		List<Order> orders = new ArrayList<Order>();

		long queryLastMainOrderId = req.getLastOrderId();

		try {

			MongoTemplate template = new MongoOrderConfig().mongoTemplate();

			//add 03-28 传入订单列表，忽略其它参数
			if (DataUtil.isNullOrEmpty(req.getOrderIdList())) {

				if (req.getLastOrderId() > 0
						&& req.isLastOrderIdIsRealOrderId()) {
					Query query = new Query();
					query.fields().include(UserIndexField.MAIN_ORDER_ID);
					UserIndex userIndex = new UserIndexQueryWapper()
							.findByIdWithQuery(query, req.getLastOrderId(),
									req.getBuyerId());
					if (userIndex != null) {
						queryLastMainOrderId = userIndex.getMainOrderId();
					}
				}

				if (queryLastMainOrderId > 0) {
					criteriaList.add(Criteria.where(
							UserIndexField.MAIN_ORDER_ID).lt(
							queryLastMainOrderId));
				}

				criteriaList.add(Criteria.where(OrderField.USER_ID).is(
						req.getBuyerId()));
				criteriaList.add(Criteria.where(OrderField.DELETED).is(false));

				if (!DataUtil.isNullOrEmpty(req.getOrderStatusList())) {
					criteriaList.add(Criteria.where(OrderField.TRADING_STATUS)
							.in(req.getOrderStatusList()));
				}

				if (!StringUtils.isBlank(req.getProductId())
						|| !StringUtils.isBlank(req.getTitle())) {
					Criteria products = Criteria.where(OrderField.PRODUCTS);
					Criteria elemMatch = null;
					if (!StringUtils.isBlank(req.getProductId())) {
						elemMatch = Criteria.where("prdId").is(
								req.getProductId());
					}
					if (!StringUtils.isBlank(req.getTitle())) {
						Criteria title = Criteria.where("title").regex(
								req.getTitle());
						if (elemMatch == null) {
							elemMatch = title;
						} else {
							elemMatch.andOperator(title);
						}
					}
					products.elemMatch(elemMatch);
					criteriaList.add(products);
				}
				if (req.getLastOrderId() > 0
						&& req.isLastOrderIdIsRealOrderId()) {
					criteriaList.add(Criteria.where(OrderField.MAIN_ORDER_ID)
							.lt(req.getLastOrderId()));
				}

				Query query = new Query(new Criteria().andOperator(criteriaList
						.toArray(new Criteria[criteriaList.size()])));

				query.with(new Sort(Sort.Direction.DESC,
						OrderField.MAIN_ORDER_ID));
				query.limit(200);

				orders = template.find(query, Order.class, SchemaField.ORDER);

			} else {

				Query query = Query.query(Criteria.where("_id").in(
						req.getOrderIdList()));

				orders = template.find(query, Order.class, SchemaField.ORDER);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return orders;
	}
	public void constructExpectedResult(GetBuyerOrderInfosResp resp) {
		List<Criteria> criteriaList = new ArrayList<Criteria>();
		//处理所有数据，内存分页，找出分页条数的主单号和订单号
		Long lastMainOrderId = null;
		List<Long> orderIds = new ArrayList<Long>();

		//商品ID不为空，或商品title不为空  程序走ES查询(用例改为查mongo)
		List<Order> orderList = getBuyerOrders(criteriaList);
		if (!CollectionUtils.isEmpty(orderList)) {
			Set<Long> mainOrderIdSet = new HashSet<Long>();
			int length = orderList.size();
			for (int i = 0; i < length; i++) {
				long mainOrderId = orderList.get(i).getMainOrderId();

				if (mainOrderIdSet.size() != req.getOrderNum()) {
					mainOrderIdSet.add(mainOrderId);
					lastMainOrderId = mainOrderId;
				}
				// 如查当前mainorderId 小于最后一个mainorderId 则退出
				if (lastMainOrderId != null && mainOrderId < lastMainOrderId) {
					break;
				}
				orderIds.add(orderList.get(i).getId());
			}

			List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
			if (!CollectionUtils.isEmpty(orderIds)) {
				List<Order> orders = new OrderQueryWapper().findByIds(orderIds);
				// 按主单号降序排序
				Collections.sort(orders, (o1, o2) -> o2.getMainOrderId()
						.compareTo(o1.getMainOrderId()));
				orders.forEach(o -> {
					ConvertUtils.convertBigDecimal(o);
					orderInfoList.add(OrderInfoBuilder.convertFromOrder(o,
							false));
				});
			}
			if (!DataUtil.isNullOrEmpty(req.getOrderIdList())) {
				lastMainOrderId = null;
			}
			resp.setOrderInfos(orderInfoList);
			resp.setLastOrderId(lastMainOrderId);
		}
	}

	private void verify() {
		GetBuyerOrderInfosResp expectResponse = new GetBuyerOrderInfosResp();
		constructExpectedResult(expectResponse);
		GetBuyerOrderInfosResp actualResponse = call
				.getBuyerOrderInfosResponseV2();
		DataUtil.verify(expectResponse.getLastOrderId(),
				actualResponse.getLastOrderId(), "验证LastOrderId");

		List<OrderInfo> expectOrders = expectResponse.getOrderInfos();
		List<OrderInfo> actualOrders = actualResponse.getOrderInfos();
		if (expectOrders == null) {
			DataUtil.verify(null, actualOrders, "验证OrderInfos == null");
		}
		for (int i = 0; i < expectOrders.size(); i++) {
			OrderInfo expect = expectOrders.get(i);
			OrderInfo actual = actualOrders.get(i);
			expect.verify(actual);
			BargainGroupInfo expBargainGroupInfo = getBargainGroupInfoFromMssql((int) expect
					.getOrderId());
			BargainGroupInfo actBargainGroupInfo = actual.getBargainGroup();
			Logger.comment("验证砍价团信息, 比对sqlserver数据");
			if (expBargainGroupInfo == null) {
				DataUtil.verify(
						null,
						actBargainGroupInfo,
						String.format(
								"验证 sqlserver中订单id:%d 没有参加砍价团(orderInfos.bargainGroup == null)",
								expect.getOrderId()));
			} else {
				DataUtil.verifyObject(expBargainGroupInfo, actBargainGroupInfo,
						"砍价团信息orderInfos.bargainGroup");
			}
		}
	}

	public BargainGroupInfo getBargainGroupInfoFromMssql(int orderId) {
		BargainGroupInfo info = null;
		Map<String, Integer> m = new HashMap<String, Integer>();
		m.put("orderId", orderId);
		List<BizVo> BizVoList = new Ts_ChangeOrderBizStatus()
				.getBizVosFromMssql(m);
		if (!DataUtil.isNullOrEmpty(BizVoList)) {
			info = new BargainGroupInfo();
			info.setBizId(BizVoList.get(0).getBizId());
			info.setBizStatus(BizVoList.get(0).getBizStatus());
			info.setBizSubType(BizVoList.get(0).getBizSubType());
		}
		return info;
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_001() {
		Logger.start(true, "订单状态为1 获取买家订单列表, 参数全传(根据orderid查)，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_002() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 只传必填字段BuyuerId,OrderNum，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_003() {
		Logger.start(true, "获取买家订单列表, OrderNum为必填");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setLastOrderId(112443995);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			Logger.verifyEquals("400", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_004() {
		Logger.start(true, "获取买家订单列表, BuyerId为必填");
		try {
			req.setOrderNum(10);
			req.setLastOrderId(0);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			Logger.verifyEquals("400", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_006() {
		Logger.start(true, "获取买家订单列表, 必填字段+LastOrderIdIsRealOrderId,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			call.setData(req);
			call.callService();

			req.setLastOrderId(call.getBuyerOrderInfosResponseV2()
					.getLastOrderId());

			call.setData(req);
			call.callService();

			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_007() {
		Logger.start(true, "获取买家订单列表, 必填字段+orderStatusList,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			//orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_008() {
		Logger.start(true, "获取买家订单列表, 必填字段+RefundedOrderOnly,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_009() {
		Logger.start(true, "获取买家订单列表, 必填字段+ToBeEvaluatedDays,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_010() {
		Logger.start(true, "删除的订单不在列表范围内");
		try {
			Logger.comment("准备一个删除的订单");
			OrderCallService orderCallService = new OrderCallService();
			orderCallService.createM2cOrder();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();

			orderCallService.salesMarkOrderDeleted(orderId, userId, true);
			Logger.comment("订单准备完成");

			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	/**
	 * 恢复删除的功能目前没有需求，不需要测试
	 */
	public void Tc_GetBuyerOrderInfosV2_011() {
		Logger.start(true, "恢复删除的订单需要返回给用户");
		try {
			Logger.comment("准备一个恢复删除的订单");
			OrderCallService orderCallService = new OrderCallService();
			orderCallService.createM2cOrder();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			orderCallService.salesMarkOrderDeleted(orderId, userId, true);
			orderCallService.salesMarkOrderDeleted(orderId, userId, false);
			Logger.comment("订单准备完成");

			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_012() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品title 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setTitle("智力车厘子");
			call.setData(req);
			call.callService();
			//verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_013() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			//req.setTitle("7cc6be1ab667");
			req.setProductId("26ce09f4-5319-487a-bf11-7cc6be1ab667");
			call.setData(req);
			call.callService();
			//verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_014() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setTitle("测试");
			call.setData(req);
			call.callService();

			req.setLastOrderId(call.getBuyerOrderInfosResponseV2()
					.getLastOrderId());
			req.setLastOrderIdIsRealOrderId(true);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_015() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			//req.setTitle("7cc6be1ab667");
			req.setProductId("26ce09f4-5319-487a-bf11-7cc6be1ab667");
			call.setData(req);
			call.callService();
			//verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_016() {
		Logger.start(true, "验证砍价团信息，查询成功, 团长开团 组团失败");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.BARGAINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.GRP_FAIL.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_017() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团失败");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.BARGAINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.CRT_FAIL.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_018() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团初始状态");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.BARGAINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.INITIAL.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_019() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团成功");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.BARGAINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.CRT_SUCCESS.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_020() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 组团成功");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.BARGAINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.GRP_SUCCESS.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_021() {
		Logger.start(true, "验证砍价团信息，查询成功, 参团(团员) 参团失败");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.JOINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.JOIN_FAIL.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_022() {
		Logger.start(true, "验证砍价团信息，查询成功, 参团(团员) 参团成功");
		try {
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			SyncVerifyService.getSyncResult(orderId);

			BizVo bizVo = new BizVo();
			bizVo.setOrderId(orderId);
			bizVo.setBizSubType(BargainGroupSubTypeEnum.JOINER.getValue()); //1：开团(团长)  2：参团(团员)
			bizVo.setBizStatus(BargainGroupStatusEnum.JOIN_SUCCESS.getValue()); //砍价团状态(-3：组团失败 -2：参团失败 -1：开团失败  0：初始状态 1：开团成功 2：参团成功 3：组团成功)
			bizVo.setBizType(1);
			bizVo.setBizId(placeOrderResp.getBizId());

			List<BizVo> bizVos = new ArrayList<BizVo>();
			bizVos.add(bizVo);

			ChangeOrderBizStatusBean changeorderbizstatusBean = new ChangeOrderBizStatusBean();
			changeorderbizstatusBean.setBizVos(bizVos);
			ChangeOrderBizStatusCall changeorderbizstatusCall = new ChangeOrderBizStatusCall();
			changeorderbizstatusCall.setData(changeorderbizstatusBean);
			changeorderbizstatusCall.callService();

			Thread.sleep(2000l);

			req.setBuyerId(placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_023() {

		Logger.start(true, "传入订单列表，查询成功");

		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());

			req.setBuyerId(userId);
			req.setOrderNum(10);
			//req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);

			req.setOrderIdList(Arrays.asList(112524246, 112524219, 112523911,
					112523726, 112521964, 112521960, 112521421, 112518359,
					112518240));

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}